<?php

/**
 * @author phuocndt
 * @copyright 2010
 * ushop.vn on facebook apps
 */
// phuocndt - Config site
error_reporting(1); 
include '../../global/includes/configure.php';

// Include Smarty
    include GLOBAL_PACKAGE_SHOPPING . 'smarty_lib/' . 'Smarty.class.php';
    $smarty = new Smarty();
    $smarty->caching = 0;
    $smarty->allow_php_tag = true;
    $smarty->template_dir = GLOBAL_PACKAGE_SHOPPING . 'facebook';
    $smarty->compile_dir  = GLOBAL_PACKAGE_SHOPPING . 'facebook';      
    $smarty->assign('GLOBAL_PACKAGE_SHOPPING', GLOBAL_PACKAGE_SHOPPING);
    $smarty->assign('DIR_WS_CATALOG', DIR_WS_CATALOG);

// Include Doctrine
    //require_once GLOBAL_PACKAGE_SHOPPING . 'doctrine/Doctrine.php';
    //spl_autoload_register(array('Doctrine', 'autoload')); // Register autoload
    //$registry->manager = Doctrine_Manager::getInstance();
    //Make database connection
    //$dsn = 'mysql:dbname=phuhane1_ushop;host=localhost';
    //$user = 'phuhane1_ushop';
    //$password = 'QvJ6O1vL';
    //$dbh = new PDO($dsn, $user, $password);
    //$dbh = new PDO(DSN, USER, PASSWD);    
    //$conn = Doctrine_Manager::connection($dbh);
    
// Include class currencies
    include GLOBAL_PACKAGE_SHOPPING . 'facebook/' . 'currencies.php';
    $currencies = new sccurrencies($conn);
// End config site

$stmt = $conn->prepare("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, pd.products_description, if(s.status, s.specials_new_products_price, p.products_price) as products_price from products p left join specials s on p.products_id = s.products_id, products_description pd where p.products_status = '1' and p.products_id = pd.products_id order by p.products_date_added desc limit 0,20");
$stmt->execute();
$result = $stmt->fetchAll();
$i=0;
foreach($result as $r){
    $tmp = array(
        'proID' => $r['products_id'],
        'proName' => $r['products_name'],
        'proImage' => $r['products_image'],
        'proPrice'=> $currencies->display_price($r['products_price']),
        'proDes'=> $r['products_description']
    );
    $result[$i++] = $tmp;
} 
/*foreach($result as $re){
    $products_image = $re['products_image'];
    $products_price = $currencies->display_price($re['products_price'], tep_get_tax_rate($re['products_tax_class_id']));
    $products_name = $re['products_name'];
    $products_description = $re['products_description'];
?>
<div class="product">
    <div class="product-thumb">
        <img class="images" src="<?php echo DIR_WS_CATALOG.'images/'.$products_image; ?>" title="<?php echo $products_name; ?>" alt="<?php echo $products_name; ?>" />
    </div>
    <div class="product-price">
        <?php echo $products_price; ?>        
    </div>
    <div class="product-tit">
        <?php echo $products_name; ?>
    </div>
    <div class="product-des">
        <?php echo $products_description; ?>
    </div>         
</div>
<?php
}*/

$stmt = $conn->prepare("select * from ushop_fb_config where id = 1");
$stmt->execute();
$result_fb = $stmt->fetchAll();

$smarty->assign('result_fb', $result_fb);
$smarty->assign('result', $result);
$smarty->display('index.tpl');
?>